import $V from './$V';
import ema from './ema';

export default  function cv(high, low, length) {
    let cvValue = $V.init(high.length, 0);
    let hiloma = ema($V.sub(high, low), length);
    let tmp = $V.init(high.length, 0);
    tmp = $V.copy_by_index(tmp, length, $V.subv(hiloma, 0, high.length - length));
    cvValue = $V.mul_constant($V.div($V.sub(hiloma, tmp), tmp), 100);
    cvValue = $V.set_by_index(cvValue, $V.where(cvValue, '==', Infinity), 0);
    return cvValue;
}
